<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<jsp:include page="header.jsp"></jsp:include>
<script src="<%=request.getContextPath()%>/js/page.js" type="text/javascript"></script>
<title>图片展示</title>
</head>
<style>

body{
  font-family: "华文细黑";
  width: 100%;
  height:auto;
  background:url(<%=request.getContextPath()%>/iconimage/bgkimg.jpg) no-repeat;
  background-size: 100%;
}
</style>
<script type="text/javascript">
var currentPage='${currentPage}';
var http_request ="<%=request.getContextPath() %>";
$(function(){init();allselect();});
//获取具体的所有图片
function getAllinfo(imagecode){
	location.href=http_request+"/upload/getAllinfo.do?imagecode="+imagecode;
}

//下架图集
function deleteImage(czcode){
	var showcode="";
	if(czcode=='SJ'){
		showcode="上架";
	}
	if(czcode=='XJ'){
		showcode="下架";
	}
	 if(confirm("确定"+showcode+"吗?"))
		    {
		     var atlasCodes="'";
	 	     var selectNum=$("input[name='requ_select']:checked").length;
	 	     if(selectNum==0){
	 		   alert("请至少选择一个图集!");
	 		   return false;
	 	       }
	 	       $("input[name='requ_select']").each(function(i){
	    		if($(this).prop("checked")==true){
	    			atlasCodes+=$(this).val()+"','";
	    		}
	    	   });
	 	      atlasCodes=atlasCodes.substring(0,atlasCodes.length-2);
	 	       $.ajax({
			   type: "post",
			   url: "<%=request.getContextPath()%>/upload/deleteImageatlas.do",
			   data: {"atlasCodes":atlasCodes,"czcode":czcode},
			   success: function(data){
			     if(data.state=="success"){
			    	 alert(showcode+"成功！");
			    	 window.location.href="<%=request.getContextPath()%>/upload/getAtlas.do?currentPage="+currentPage;
			    	}else{
			    	 alert(showcode+"失败！");
			     }
			   }
			});  
		 }
	}

//展示修改图集名称的div
function showupdateAtlasName(dataid){
	layer.open({
		  id: 'insert-form',
		  type: 2,
		  title: '修改图集名称',
		  skin: 'layui-layer-rim', //加上边框
		  shade: 0.8,
		  area: ['20%', '25%'],
		  btn: ['确认', '取消'],
		  content: '<%=request.getContextPath()%>/upload/showNameDiv.do?tagflag=tag1', 
		  yes:function(index,layero){
			  var iframeWin = window[layero.find('iframe')[0]['name']]; 
			//调用子页面的方法，得到子页面返回的;
		     var atlasname = iframeWin.getUpdatename();
		     updateAtlasName(dataid,atlasname);
		     layer.close(index); //关闭当前弹层
		  }
		}); 
}

//修改图集名
function updateAtlasName(dataid,updatname){
	  $.ajax({
		   type: "post",
		   url: "<%=request.getContextPath()%>/upload/updateAtlasName.do",
		   data: {"dataid":dataid,"updatname":updatname},
		   success: function(data){
		     if(data.state=="success"){
		    	 alert("修改成功！");
		    	 window.location.href="<%=request.getContextPath()%>/upload/getAtlas.do?currentPage="+currentPage;
		    	}else{
		    	 alert("修改失败！");
		     }
		   }
		});
}
//展示标签的div
function setTagName(dataid){
	layer.open({
		  id: 'insert-form',
		  type: 2,
		  title: '修改图集名称',
		  skin: 'layui-layer-rim', //加上边框
		  shade: 0.8,
		  area: ['20%', '25%'],
		  btn: ['确认', '取消'],
		  content: '<%=request.getContextPath()%>/upload/showNameDiv.do?tagflag=tag2', 
		  yes:function(index,layero){
			  var iframeWin = window[layero.find('iframe')[0]['name']]; 
			//调用子页面的方法，得到子页面返回的;
		    var  atlasTags = iframeWin.gettags();
		     updateTags(dataid,atlasTags);
		     layer.close(index); //关闭当前弹层
		  }
		}); 

}
//修改标签
function updateTags(dataid,atlastags){
	 $.ajax({
		   type: "post",
		   url: "<%=request.getContextPath()%>/upload/updateAtlasTag.do",
		   data: {"dataid":dataid,"atlastags":atlastags},
		   success: function(data){
		     if(data.state=="success"){
		    	 alert("修改成功！");
		    	 window.location.href="<%=request.getContextPath()%>/upload/getAtlas.do?currentPage="+currentPage;
		    	}else{
		    	 alert("修改失败！");
		     }
		   }
		});
}
//修改单价
function setTagPrice(dataid){
	layer.open({
		  id: 'insert-form',
		  type: 2,
		  title: '修改图集名称',
		  skin: 'layui-layer-rim', //加上边框
		  shade: 0.8,
		  area: ['20%', '25%'],
		  btn: ['确认', '取消'],
		  content: '<%=request.getContextPath()%>/upload/showNameDiv.do?tagflag=tag3', 
		  yes:function(index,layero){
			  var iframeWin = window[layero.find('iframe')[0]['name']]; 
			//调用子页面的方法，得到子页面返回的;
		     var atlasPrice = iframeWin.getUpdatePrice();
		     updateAtlasPrice(dataid,atlasPrice);
		     layer.close(index); //关闭当前弹层
		  }
		});
	}
	
	function updateAtlasPrice(dataid,atlasPrice){
		 $.ajax({
			   type: "post",
			   url: "<%=request.getContextPath()%>/upload/updateAtlasPrice.do",
			   data: {"dataid":dataid,"atlasPrice":atlasPrice},
			   success: function(data){
			     if(data.state=="success"){
			    	 alert("修改成功！");
			    	 window.location.href="<%=request.getContextPath()%>/upload/getAtlas.do?currentPage="+currentPage;
			    	}else{
			    	 alert("修改失败！");
			     }
			   }
			});
	}

</script>
<body>
<div class="contextBox" >

 <ul class="tabs">
			<li><a href="<%=request.getContextPath()%>/upload/getAtlas.do?currentPage=1" name=".tab1_1" >所有图集</a></li>
			<li><a href="<%=request.getContextPath()%>/upload/bannerSet.do"  name=".tab1_2">轮播图设置</a></li>
			<li><a href="<%=request.getContextPath()%>/upload/showAppversion.do"  name=".tab1_3">app版本控制</a></li>
  </ul>


<form name="form" action="<%=request.getContextPath()%>/upload/getAtlas.do?currentPage=1" method="post">

<table class="TableList" width="100%" align="center">
		   <tbody><tr class="TableContent">
		   <td >
		         图集名称：<input type="text"  class="BigInput" id="atlasName" name="atlasName"  value="${atlasName}">
		        标签：<select id="atlasTags" name="atlasTags">
			      <c:forEach var="ph" items="${atlastagList}">
			      <option id="tag_00" value="" ></option>
		          <option id="tag_${ph.id}" value="${ph.tagCode}" <c:if test="${atlasTags==ph.tagCode }"> selected</c:if>  >${ph.tagName}</option>
			      </c:forEach>
		          </select>
		         是否下架：<select id="isDelete" name="isDelete">
		             <option id="" value="0"  <c:if test="${isDelete=='0' }"> selected</c:if>>否</option>
			         <option id="" value="1"  <c:if test="${isDelete=='1' }"> selected</c:if>>是</option>
			        
			          </select>
		    </td>
		     </tr>
		</tbody></table>
		<div>
		<table>
		<tbody>
		<tr>
		<td>
		<input type="submit" value="搜索"/>
		<input type="button"   onclick="clearData()" value="清空"/>
		</td>
		</tr>
		</tbody>
		</table>
		</div>

<table>
<tbody><tr>
<th width="1%" class="list_title" align="center"><input type="checkbox" name="allbox" id="allbox_for_requ"></th>
<th width="5%" class="list_title" align="center"><b>图集序号</b></th>
<th width="40%" class="list_title" align="center"><b>图集名称</b></th>
<th width="5%" class="list_title" align="center"><b>图集单价</b></th>
<th width="20%" class="list_title" align="center"><b>所属标签</b></th>
<th width="10%" class="list_title" align="center"><b>是否下架</b></th>
<th width="20%" class="list_title" align="center"><b>操作</b></th>
</tr>
<c:forEach items="${imagelist}" var="fi" varStatus="stat">		
<tr>
<td class="list_value" align="center">&nbsp;<input type="checkbox" name="requ_select" id="requ_checkbox_${fi.ID}" value="${fi.atlasCode}"></td>
<td  align="left"><span>${stat.index+1}</span></td>
<td  align="left"><a href="#" onclick="getAllinfo('${fi.atlasCode}')"><span>${fi.atlasName }</span></a></td>
<td  align="left"><span>${fi.atlasPrice }元</span></td>
<td  align="left"><span>${fi.imageTital }</span></td>
<td>
<c:if test="${fi.isDelete=='1' }">
<span><input type="button" style="background-color: #D9D9D9"  value="OFFLINE" ></span>
</c:if>
<c:if test="${fi.isDelete=='0' }">
<span><input type="button" style="background-color: #E0FFFF"   value="ONLINE" ></span>
</c:if>
</td>
<td  align="right"> 
<c:if test="${fi.isDelete=='1' }">
<span><input type="button"  value="重新上架" onclick="deleteImage('SJ')"></span>
</c:if>
<c:if test="${fi.isDelete=='0' }">
<span><input type="button"  value="下架" onclick="deleteImage('XJ')"></span>
</c:if>

<span><input type="button"  value="修改名称" onclick="showupdateAtlasName(${fi.ID})"></span>
<span><input type="button"  value="设置标签" onclick="setTagName(${fi.ID})"></span>
<span><input type="button"  value="设置单价" onclick="setTagPrice(${fi.ID})"></span>
</td>
</tr>
</c:forEach>
</tbody>
</table>
	<table>
		<tbody>
		<tr>
		<td>
	<input type="hidden" name="currentPage" value="${currentPage}" /> 
			<input type="hidden" name="pageCount" value="${pageCount}"/> 
			<input type="hidden" name="count" value="${count}"/>
			<input type="button" name="first1" value="首页" onclick="first()" class="button gray" /> 
			<input type="button" name="pre1" value="上一页" onclick="pre()" class="button green"/> 
			<input type="button" name="next1" value="下一页" onclick="next()" class="button blue"/> 
			<input type="button" name="end1" value="尾页" onclick="end()" class="button gray"/> 
			<font>第${currentPage}页, 共${pageCount}页,共${count}条数据</font>
		</td>
		</tr>
		</tbody>
		</table>
</div>
<div>
</form>
</div>

</body>
</html>